package com.xie.smfs.screen;

import com.xie.smfs.handler.SecondInventoryScreenHandler;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

public class SecondInventoryScreen extends HandledScreen<SecondInventoryScreenHandler> {
    // 使用原版制图台的纹理
    private static final Identifier TEXTURE = new Identifier("minecraft", "textures/gui/container/cartography_table.png");

    public SecondInventoryScreen(SecondInventoryScreenHandler handler, PlayerInventory inventory, Text title) {
        super(handler, inventory, title);
        this.backgroundWidth = 176;
        this.backgroundHeight = 166;
    }

    @Override
    protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
        int x = (width - backgroundWidth) / 2;
        int y = (height - backgroundHeight) / 2;

        // 绘制制图台背景
        context.drawTexture(TEXTURE, x, y, 0, 0, backgroundWidth, backgroundHeight);

        // 绘制合成槽位的背景（使用制图台的槽位位置）
        // 输入槽1 (原版制图台的地图槽位)
        context.drawTexture(TEXTURE, x + 15, y + 20, 176, 0, 18, 18);
        // 输入槽2 (原版制图台的纸张槽位)
        context.drawTexture(TEXTURE, x + 15, y + 56, 176, 0, 18, 18);
        // 输出槽 (原版制图台的输出槽位)
        context.drawTexture(TEXTURE, x + 139, y + 39, 176, 0, 26, 26);
    }

    @Override
    public void render(DrawContext context, int mouseX, int mouseY, float delta) {
        renderBackground(context);
        super.render(context, mouseX, mouseY, delta);
        drawMouseoverTooltip(context, mouseX, mouseY);
    }

    @Override
    protected void init() {
        super.init();
        // 将标题位置调整到制图台界面的合适位置
        titleX = 8;
        titleY = 6;
        playerInventoryTitleY = 72;
    }
}